package com.woniu.supermarket.web;


import com.alibaba.excel.EasyExcelFactory;
import com.github.pagehelper.PageInfo;
import com.woniu.supermarket.entity.FinancialDetail;
import com.woniu.supermarket.result.ResultResponse;
import com.woniu.supermarket.service.IFinancialDetailService;
import com.woniu.supermarket.vo.CollectionSummaryVo;
import com.woniu.supermarket.vo.RefundSummaryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("financialDetail")
@Api(value = "财务操作")
public class FinancialDetailController {

    @Autowired
    IFinancialDetailService iFinancialDetailService;

    @GetMapping("/show")
    @ApiOperation(value = "财务收银明细分页查询")
    public ResultResponse<PageInfo<FinancialDetail>> showFinancialDetail(@ApiParam(name = "now",value = "当前页") @RequestParam(name = "now",defaultValue = "1") Integer now,
                                                               @ApiParam(name = "size",value = "页大小") @RequestParam(name = "size",defaultValue = "3") Integer size,
                                                               @ApiParam(name = "number",value = "订单号") String number){

        ResultResponse<PageInfo<FinancialDetail>> result = null;
        try {
            PageInfo<FinancialDetail> pageInfo = iFinancialDetailService.findByConds(now, size, number);
            result = new ResultResponse<>(200,"查询财务收银明细成功",pageInfo);
        }catch (RuntimeException e){
            e.printStackTrace();
            result = new ResultResponse<>(201,"查询财务收银明细失败");
        }
        return result;
    }

    @GetMapping("/showByDay")
    @ApiOperation(value = "财务收银收款汇总（日）")
    public ResultResponse<PageInfo<CollectionSummaryVo>> showCollectionSummaryByDay(@ApiParam(name = "now",value = "当前页") @RequestParam(name = "now",defaultValue = "1") Integer now,
                                                                               @ApiParam(name = "size",value = "页大小") @RequestParam(name = "size",defaultValue = "3") Integer size
                                                                             ){

        ResultResponse<PageInfo<CollectionSummaryVo>> result = null;
        try {
            PageInfo<CollectionSummaryVo> pageInfo = iFinancialDetailService.findCollectionSummaryVoByConds(now, size);
            result = new ResultResponse<>(200,"查询财务收银汇总成功",pageInfo);
        }catch (RuntimeException e){
            e.printStackTrace();
            result = new ResultResponse<>(201,"查询财务收银汇总失败");
        }
        return result;
    }

    @GetMapping("/showByMonth")
    @ApiOperation(value = "财务收银收款汇总(月)")
    public ResultResponse<PageInfo<CollectionSummaryVo>> showCollectionSummaryByMonth(@ApiParam(name = "now",value = "当前页") @RequestParam(name = "now",defaultValue = "1") Integer now,
                                                                               @ApiParam(name = "size",value = "页大小") @RequestParam(name = "size",defaultValue = "3") Integer size
    ){

        ResultResponse<PageInfo<CollectionSummaryVo>> result = null;
        try {
            PageInfo<CollectionSummaryVo> pageInfo = iFinancialDetailService.findCollectionSummaryVoByMonthByConds(now, size);
            result = new ResultResponse<>(200,"查询财务收银汇总成功",pageInfo);
        }catch (RuntimeException e){
            e.printStackTrace();
            result = new ResultResponse<>(201,"查询财务收银汇总失败");
        }
        return result;
    }

    @GetMapping("/showByYear")
    @ApiOperation(value = "财务收银收款汇总(年)")
    public ResultResponse<PageInfo<CollectionSummaryVo>> showCollectionSummaryByYear(@ApiParam(name = "now",value = "当前页") @RequestParam(name = "now",defaultValue = "1") Integer now,
                                                                                      @ApiParam(name = "size",value = "页大小") @RequestParam(name = "size",defaultValue = "3") Integer size
    ){

        ResultResponse<PageInfo<CollectionSummaryVo>> result = null;
        try {
            PageInfo<CollectionSummaryVo> pageInfo = iFinancialDetailService.findCollectionSummaryVoByYearByConds(now, size);
            result = new ResultResponse<>(200,"查询财务收银汇总成功",pageInfo);
        }catch (RuntimeException e){
            e.printStackTrace();
            result = new ResultResponse<>(201,"查询财务收银汇总失败");
        }
        return result;
    }


    @GetMapping("/showByDayR")
    @ApiOperation(value = "财务收银退款汇总（日）")
    public ResultResponse<PageInfo<RefundSummaryVo>> showRefundSummaryByDay(@ApiParam(name = "now",value = "当前页") @RequestParam(name = "now",defaultValue = "1") Integer now,
                                                                                    @ApiParam(name = "size",value = "页大小") @RequestParam(name = "size",defaultValue = "3") Integer size
    ){

        ResultResponse<PageInfo<RefundSummaryVo>> result = null;
        try {
            PageInfo<RefundSummaryVo> pageInfo = iFinancialDetailService.findRefundSummaryVoByConds(now, size);
            result = new ResultResponse<>(200,"查询财务收银退款汇总成功",pageInfo);
        }catch (RuntimeException e){
            e.printStackTrace();
            result = new ResultResponse<>(201,"查询财务收银退款汇总失败");
        }
        return result;
    }

    @GetMapping("/showByMonthR")
    @ApiOperation(value = "财务收银退款汇总(月)")
    public ResultResponse<PageInfo<RefundSummaryVo>> showRefundSummaryByMonth(@ApiParam(name = "now",value = "当前页") @RequestParam(name = "now",defaultValue = "1") Integer now,
                                                                                      @ApiParam(name = "size",value = "页大小") @RequestParam(name = "size",defaultValue = "3") Integer size
    ){

        ResultResponse<PageInfo<RefundSummaryVo>> result = null;
        try {
            PageInfo<RefundSummaryVo> pageInfo = iFinancialDetailService.findRefundSummaryVoByMonthByConds(now, size);
            result = new ResultResponse<>(200,"查询财务收银退款汇总成功",pageInfo);
        }catch (RuntimeException e){
            e.printStackTrace();
            result = new ResultResponse<>(201,"查询财务收银退款汇总失败");
        }
        return result;
    }

    @GetMapping("/showByYearR")
    @ApiOperation(value = "财务收银退款汇总(年)")
    public ResultResponse<PageInfo<RefundSummaryVo>> showRefundSummaryByYear(@ApiParam(name = "now",value = "当前页") @RequestParam(name = "now",defaultValue = "1") Integer now,
                                                                                     @ApiParam(name = "size",value = "页大小") @RequestParam(name = "size",defaultValue = "3") Integer size
    ){

        ResultResponse<PageInfo<RefundSummaryVo>> result = null;
        try {
            PageInfo<RefundSummaryVo> pageInfo = iFinancialDetailService.findRefundSummaryVoByYearByConds(now, size);
            result = new ResultResponse<>(200,"查询财务退款汇总成功",pageInfo);
        }catch (RuntimeException e){
            e.printStackTrace();
            result = new ResultResponse<>(201,"查询财务退款汇总失败");
        }
        return result;
    }

    @GetMapping("/showCollectionSummaryByDayExport")
    @ApiOperation(value = "财务收银收款汇总（日）导出")
    public ResultResponse<List<CollectionSummaryVo>> showCollectionSummaryByDayExport(){

        ResultResponse<List<CollectionSummaryVo>> result = null;
        try {
            List<CollectionSummaryVo> list = iFinancialDetailService.findAllCollectionSummaryVoByDay();
            result = new ResultResponse<>(200,"查询财务收银汇总成功",list);
        }catch (RuntimeException e){
            e.printStackTrace();
            result = new ResultResponse<>(201,"查询财务收银汇总失败");
        }
        return result;
    }
    @GetMapping("/showCollectionSummaryByMonthExport")
    @ApiOperation(value = "财务收银收款汇总（月）导出")
    public ResultResponse<List<CollectionSummaryVo>> showCollectionSummaryByMonthExport(){

        ResultResponse<List<CollectionSummaryVo>> result = null;
        try {
            List<CollectionSummaryVo> list = iFinancialDetailService.findAllCollectionSummaryVoByMonth();
            result = new ResultResponse<>(200,"查询财务收银汇总成功",list);
        }catch (RuntimeException e){
            e.printStackTrace();
            result = new ResultResponse<>(201,"查询财务收银汇总失败");
        }
        return result;
    }
    @GetMapping("/showCollectionSummaryByYearExport")
    @ApiOperation(value = "财务收银收款汇总（年）导出")
    public ResultResponse<List<CollectionSummaryVo>> showCollectionSummaryByYearExport(){

        ResultResponse<List<CollectionSummaryVo>> result = null;
        try {
            List<CollectionSummaryVo> list = iFinancialDetailService.findAllCollectionSummaryVoByYear();
            result = new ResultResponse<>(200,"查询财务收银汇总成功",list);
        }catch (RuntimeException e){
            e.printStackTrace();
            result = new ResultResponse<>(201,"查询财务收银汇总失败");
        }
        return result;
    }


    @GetMapping("/showRefundSummaryByDayExport")
    @ApiOperation(value = "财务收银收款汇总（日）导出")
    public ResultResponse<List<RefundSummaryVo>> showRefundSummaryByDayExport(){

        ResultResponse<List<RefundSummaryVo>> result = null;
        try {
            List<RefundSummaryVo> list = iFinancialDetailService.findAllRefundSummaryByDay();
            result = new ResultResponse<>(200,"查询财务收银汇总成功",list);
        }catch (RuntimeException e){
            e.printStackTrace();
            result = new ResultResponse<>(201,"查询财务收银汇总失败");
        }
        return result;
    }
    @GetMapping("/showRefundSummaryByMonthExport")
    @ApiOperation(value = "财务收银收款汇总（月）导出")
    public ResultResponse<List<RefundSummaryVo>> showRefundSummaryByMonthExport(){

        ResultResponse<List<RefundSummaryVo>> result = null;
        try {
            List<RefundSummaryVo> list = iFinancialDetailService.findAllRefundSummaryByMonth();
            result = new ResultResponse<>(200,"查询财务收银汇总成功",list);
        }catch (RuntimeException e){
            e.printStackTrace();
            result = new ResultResponse<>(201,"查询财务收银汇总失败");
        }
        return result;
    }
    @GetMapping("/showRefundSummaryByYearExport")
    @ApiOperation(value = "财务收银收款汇总（年）导出")
    public ResultResponse<List<RefundSummaryVo>> showRefundSummaryByYearExport(){

        ResultResponse<List<RefundSummaryVo>> result = null;
        try {
            List<RefundSummaryVo> list = iFinancialDetailService.findAllRefundSummaryByYear();
            result = new ResultResponse<>(200,"查询财务收银汇总成功",list);
        }catch (RuntimeException e){
            e.printStackTrace();
            result = new ResultResponse<>(201,"查询财务收银汇总失败");
        }
        return result;
    }




}
